extends LightSwitch

@onready var body: MeshInstance3D = $StaticBody3D/CollisionShape3D/body
@onready var switch: MeshInstance3D = $StaticBody3D/CollisionShape3D/switch

const TEST_LIGH_SWITCH_DARK = preload("res://assets/materials/test_ligh_switch/test_ligh_switch_dark.tres")
const TEST_LIGH_SWITCH_GLOWING = preload("res://assets/materials/test_ligh_switch/test_ligh_switch_glowing.tres")

func _ready() -> void:
	super._ready()
	sync_state()

func interact(params: Dictionary = {}) -> void:
	super.interact(params)
	sync_state()

func sync_state():
	if isActive:
		switch.rotation.z = deg_to_rad(20)
		body.set_surface_override_material(1, TEST_LIGH_SWITCH_DARK)
	else:
		switch.rotation.z = deg_to_rad(0)
		body.set_surface_override_material(1, TEST_LIGH_SWITCH_GLOWING)
